//
// Created by wxd on 2025/9/11.
//

#ifndef RENDERER_H
#define RENDERER_H

#include "IRenderer.h"
#include "../glFramework/demo/light/AmbientLight.h"
#include "../glFramework/demo/light/ParallelLight.h"
#include "../glFramework/demo/light/Light.h"
#include "../glFramework/geo/BaseGeometry.h"
#include "../glFramework/demo/material/Material.h"
#include "../glFramework/demo/material/IMaterial.h"
#include "../glFramework/demo/material/PhongMaterial.h"
#include "../glFramework/demo/mesh/Mesh.h"
#include "../application/camera/BaseCamera.h"
#include "../application/camera/PerspectiveCamera.h"
#include "../application/camera/OrthogonalCamera.h"
#include "../glFramework/demo/light/PointLight.h"
#include "../glFramework/demo/light/SpotLight.h"

#include <vector>
#include <string>
#include <mutex>
#include <glm/glm.hpp>
#include <iostream>
#include <sstream>
#include <memory>
#include <sstream>

class Renderer : public IRenderer {
public:
    Renderer();
    ~Renderer();

    // 测试相关的接口，非最终的引擎设计接口

    /**
     * 环境光 + 平行光的Phong氏光照模型渲染
     * C++中的普通引用类型是无法作为C++中提供的相关容器list,vector等等的元素，必须通过std::reference_wrapper包装
     * 否则存在编译错误
     */
    static void render(BaseCamera& camera,
                       std::vector<std::reference_wrapper<Mesh>> &meshQueue,
                       AmbientLight& ambientLight,ParallelLight& parallelLight);

    /**
     * 测试全局的着色器管理器，
     */
    static void render_V2(BaseCamera& camera,
                          std::vector<std::reference_wrapper<Mesh>> &meshQueue,
                          AmbientLight& ambientLight, ParallelLight& parallelLight);


    /**
     * 点光源Phong光照渲染
     */
    static void render_V3(BaseCamera& camera, std::vector<std::reference_wrapper<Mesh>> &meshQueue,
                          AmbientLight& ambientLight, PointLight& pointLight);


    /**
     * 聚光灯Phong光照渲染
     */
    static void render_V4(BaseCamera& camera,
                          std::vector<std::reference_wrapper<Mesh>> &meshQueue,
                          AmbientLight& ambientLight, SpotLight& spotLight);

    /**
     * 多光源类型的Phong氏光照渲染
     */
    static void render_V5(BaseCamera& camera, std::vector<std::reference_wrapper<Mesh>> &meshQueue,
                          AmbientLight& ambientLight, ParallelLight& parallelLight, PointLight& pointLight, SpotLight& spotLight);
private:
    std::mutex mRenderLock {};

    static void uniformMvp(Shader& shader, const glm::mat4& m, const glm::mat4& v, const glm::mat4& p);

};

#endif //RENDERER_H
